<template>
  <div class="breadcrumb-wrapper">
    <div class="title">当前位置：</div>
    <el-breadcrumb separator="/">    
      <el-breadcrumb-item
          :to="{ query: { pid: ROOT_PATH, fileType: fileType().current() } }"
      >{{FILE_TYPE_MAP[fileType().current()]}}</el-breadcrumb-item>
		
      <el-breadcrumb-item
          v-for="(item, index) in breadCrumbList"
          :key="index"
          :to="{ query: { pid: item.id, fileType: FILE_TYPE.ALL } }"
      >{{item.name}}</el-breadcrumb-item>      
    </el-breadcrumb>
  </div>
</template>

<script>
import { wangpanGlobal }  from '/@/utils/wangpanGlobalConst';
import {fileType, filePath} from '/@/utils/wangpanGlobalFunction';
import { useStore } from '/@/store/index';
import { computed, toRefs, reactive } from 'vue';

export default {
  name: 'wangpanBreadCrumb',
  setup(){
  	const store=useStore();
  	
  	const state=reactive({
  		ROOT_PATH: wangpanGlobal.gROOT_PATH,
	  	FILE_TYPE: wangpanGlobal.gFILE_TYPE,
	  	FILE_TYPE_MAP: wangpanGlobal.gFILE_TYPE_MAP,
  	});

  	const breadCrumbList=computed(()=>{
  		return getPathTree(filePath().current());
  	});

  	const getPathTree = (path) =>{
        let list = []
        let id = path
        while (id) {
        	if (store.state.wangpanFileList.pathTreeMap[id])
        	{
	            list.push(store.state.wangpanFileList.pathTreeMap[id])
	            id = store.state.wangpanFileList.pathTreeMap[id].pid
            }
            else break;
        }
        return list.reverse();
    };

  	return{
  		...toRefs(state),
  		breadCrumbList,
  		fileType,
  		
  	};
  }, 
}
</script>
<style lang="stylus" scoped>
.breadcrumb-wrapper
  padding 0
  height 30px
  line-height 30px
  display flex

  .title, :deep(.el-breadcrumb)
    height 30px
    line-height 30px
</style>
